#pragma once

#include "Session.h"
#include "Dispatcher.h"

namespace wsbus {

	class Listener : public std::enable_shared_from_this<Listener>
	{
	public:
		Listener(tcp::endpoint endpoint, int threads = 3);
		void run();
		bool isBindSuccess() const { return isBindSuccess_; }

	private:
		void doAccept();
		void onAccept(beast::error_code ec, tcp::socket socket);

	private:
		int threads_;
		net::io_context ctx_;
#ifdef WS_SSL
		ssl::context sslctx_{ ssl::context::tlsv12 };
#endif
		tcp::acceptor acceptor_;
		Dispatcher dispatcher_;
		bool isBindSuccess_;
	};

}